/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.unmsm.cinfo.siga.datos;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author lartkma
 */
@Entity
@Table(name = "PROGRAMA_MODULO")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ProgramaModulo.findAll", query = "SELECT p FROM ProgramaModulo p"),
    @NamedQuery(name = "ProgramaModulo.findByProCod", query = "SELECT p FROM ProgramaModulo p WHERE p.programaModuloPK.proCod = :proCod"),
    @NamedQuery(name = "ProgramaModulo.findByModCod", query = "SELECT p FROM ProgramaModulo p WHERE p.programaModuloPK.modCod = :modCod"),
    @NamedQuery(name = "ProgramaModulo.findByPromOrd", query = "SELECT p FROM ProgramaModulo p WHERE p.promOrd = :promOrd"),
    @NamedQuery(name = "ProgramaModulo.findByPromEst", query = "SELECT p FROM ProgramaModulo p WHERE p.promEst = :promEst")})
public class ProgramaModulo implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ProgramaModuloPK programaModuloPK;
    @Column(name = "PROM_ORD")
    private Integer promOrd;
    @Column(name = "PROM_EST")
    private Short promEst;
    @JoinColumn(name = "MOD_COD", referencedColumnName = "MOD_COD", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Modulo modulo;
    @JoinColumn(name = "PRO_COD", referencedColumnName = "PRO_COD", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Programa programa;
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);

    public ProgramaModulo() {
    }

    public ProgramaModulo(ProgramaModuloPK programaModuloPK) {
        this.programaModuloPK = programaModuloPK;
    }

    public ProgramaModulo(int proCod, int modCod) {
        this.programaModuloPK = new ProgramaModuloPK(proCod, modCod);
    }

    public ProgramaModuloPK getProgramaModuloPK() {
        return programaModuloPK;
    }

    public void setProgramaModuloPK(ProgramaModuloPK programaModuloPK) {
        ProgramaModuloPK old = this.programaModuloPK;
        this.programaModuloPK = programaModuloPK;
        changeSupport.firePropertyChange("programaModuloPK", old, programaModuloPK);
    }

    public Integer getPromOrd() {
        return promOrd;
    }

    public void setPromOrd(Integer promOrd) {
        Integer old = this.promOrd;
        this.promOrd = promOrd;
        changeSupport.firePropertyChange("promOrd", old, promOrd);
    }

    public Short getPromEst() {
        return promEst;
    }

    public void setPromEst(Short promEst) {
        Short old = this.promEst;
        this.promEst = promEst;
        changeSupport.firePropertyChange("promEst", old, promEst);
    }

    public Modulo getModulo() {
        return modulo;
    }

    public void setModulo(Modulo modulo) {
        Modulo old = this.modulo;
        this.modulo = modulo;
        changeSupport.firePropertyChange("modulo", old, modulo);
    }

    public Programa getPrograma() {
        return programa;
    }

    public void setPrograma(Programa programa) {
        Programa old = this.programa;
        this.programa = programa;
        changeSupport.firePropertyChange("programa", old, programa);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (programaModuloPK != null ? programaModuloPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ProgramaModulo)) {
            return false;
        }
        ProgramaModulo other = (ProgramaModulo) object;
        if ((this.programaModuloPK == null && other.programaModuloPK != null) || (this.programaModuloPK != null && !this.programaModuloPK.equals(other.programaModuloPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pe.edu.unmsm.cinfo.siga.datos.ProgramaModulo[ programaModuloPK=" + programaModuloPK + " ]";
    }
    
    public void addPropertyChangeListener(PropertyChangeListener l){
        changeSupport.addPropertyChangeListener(null);
    }
    
    public void removePropertyChangeListener(PropertyChangeListener l){
        changeSupport.removePropertyChangeListener(null);
    }
}
